﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace PropertyManagement.yuanGong
{
    public partial class browerPhoto : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData(0);
            }
        }

        public void BindData(int curPageIndex)
        {
            string strsql = "select * from syuangong";
            mydata myda = new mydata();
            DataSet ds = myda.getDataSet(strsql, "syuangong");

            PagedDataSource pds = new PagedDataSource();
            pds.DataSource = ds.Tables[0].DefaultView;
            pds.AllowPaging = true;
            //int t1 = Convert.ToInt16(pds.CurrentPageIndex) + 1;
            //curPageIndex = t1;
            pds.CurrentPageIndex = curPageIndex;
            pds.PageSize = 2;
            //Label1.Text = Convert.ToString(pds.PageCount);
            // Label2.Text = Convert.ToString(curPageIndex);
            Label1.Text = pds.PageCount.ToString();
            Label2.Text = pds.CurrentPageIndex.ToString();
            // Label2.Text = Convert.ToString(t1);

            DataList1.DataSource = pds;
            DataList1.DataBind();
        }

        protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
        {
            string str1 = "", str2 = "";
            str1 = Label1.Text;
            str2 = Label2.Text;
            int n1, count;
            n1 = Int16.Parse(str2);
            count = Int16.Parse(str1);

            switch (e.CommandName)
            {
                case "first":
                    BindData(0);
                    break;
                case "prev":
                    if (n1 > 0)
                    {
                        n1 = n1 - 1;
                        BindData(n1);
                    }
                    break;
                case "next":
                    if (n1 < count - 1)
                    {
                        n1 = n1 + 1;
                        BindData(n1);
                    }
                    break;
                case "last":
                    BindData(count - 1);
                    break;
                case "return":
                    Response.Redirect("addYuanGong.aspx");
                    break;
            }
        }
    }
}